package com.dxysun.springboot.service;

import com.dxysun.springboot.service.api.ParseService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Map;

@Service
public class MyService
{

    private static final Log logger = LogFactory.getLog(MyService.class);

    @Autowired
    private Map<String, ParseService> parseServiceMap;

    @PostConstruct
    public void init()
    {
        for(Map.Entry<String,ParseService> entry : parseServiceMap.entrySet())
        {
            logger.info(entry.getKey() + " " + entry.getValue().parse("init"));
        }
    }

    public String getServiceInfo(String name,String info)
    {
        asyncTest();
        return name + " call MyService " + info ;
    }

    public ParseService getParseService(String name)
    {
        return parseServiceMap.get(name + "ParseService") ;
    }

    @Async
    public void asyncTest()
    {
        logger.info("asyncTest");
    }
}
